#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
from sage.all import *
from curves import *

# from The paper: Improved Weil and Tate pairings for elliptic and hyperelliptic curves
# found http://eprint.iacr.org/2003/242.pdf (remember that the pairing is squared)
g = 2
q = 31

Px = PolynomialRing(GF(q), 'x')
x = Px.gen()
f = x ** 5 + 13 * x ** 4 + 2 * x ** 3 + 4 * x ** 2 + 11 * x + 1
c = Curve.createSimpleCurve(f, Px)
dd = [x ** 2 + 23 * x + 15, 13 * x + 28]
ee = [x ** 2 + 4 * x + 2, 29 * x + 20]
D = c.divisorOf(dd)
E = c.divisorOf(ee)

n = 5
d = (q ** embeddingDegree(q, n) - 1) / n
resultado = c.internaMiller(n, d, D, E)

print "the result is %r" % resultado
print "the expected one is = 2"
